package com.yunfeisoft.business.model;

import com.yunfeisoft.common.base.BaseModel;
import com.yunfeisoft.common.utils.DateUtils;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * ClassName: Donation
 * Description: 捐赠物品登记
 *
 * @Author: Jackie liu
 * Date: 2020-05-14
 */
@Entity
@Table(name = "TT_DONATION")
public class Donation extends BaseModel implements Serializable {

    /**
     * Field serialVersionUID: 序列号
     */
    private static final long serialVersionUID = 1L;

    /**
     * 日期
     */
    @Column
    private Date happenDate;

    /**
     * 捐赠人
     */
    @Column
    private String name;

    /**
     * 捐赠意愿
     */
    @Column
    private String intention;

    /**
     * 类型(1钱款、2物品)
     */
    @Column
    private Integer type;

    /**
     * 金额
     */
    @Column
    private BigDecimal amount;

    /**
     * 处置意见
     */
    @Column
    private String handle;

    /**
     * 经办人
     */
    @Column
    private String handleName;

    /**
     * 备注
     */
    @Column
    private String remark;

    private List<DonationItem> donationItemList;

    public String getTypeStr() {
        return DonationTypeEnum.valueOf(type);
    }

    public String getHappenDateStr() {
        if (happenDate != null) {
            return DateUtils.dateToString(happenDate);
        }
        return null;
    }

    public Date getHappenDate() {
        return happenDate;
    }

    public void setHappenDate(Date happenDate) {
        this.happenDate = happenDate;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIntention() {
        return intention;
    }

    public void setIntention(String intention) {
        this.intention = intention;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public String getHandle() {
        return handle;
    }

    public void setHandle(String handle) {
        this.handle = handle;
    }

    public String getHandleName() {
        return handleName;
    }

    public void setHandleName(String handleName) {
        this.handleName = handleName;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public List<DonationItem> getDonationItemList() {
        return donationItemList;
    }

    public void setDonationItemList(List<DonationItem> donationItemList) {
        this.donationItemList = donationItemList;
    }

    /**
     * 类型(1钱款、2物品)
     */
    public enum DonationTypeEnum {

        MONEY(1, "钱款"),
        GOODS(2, "物品");

        private int value;
        private String label;

        private DonationTypeEnum(int value, String label) {
            this.value = value;
            this.label = label;
        }

        public static String valueOf(Integer value) {
            if (value == null) {
                return null;
            }
            for (DonationTypeEnum loop : DonationTypeEnum.values()) {
                if (value == loop.getValue()) {
                    return loop.getLabel();
                }
            }
            return null;
        }

        public int getValue() {
            return value;
        }

        public String getLabel() {
            return label;
        }

    }
}